package com.ileaf.proxy;

import com.ileaf.proxy.jdk.PeopleInvocationHandler;

import java.lang.reflect.Proxy;

/**
 * @author Lianlb
 * @date 2019-04-18 11:03
 */
public class Main {

    public static void main(String[] args) {
        String name = "小明";
        IHello hi = new PeopleImpl();
        hi.sayHello(name);
        System.out.println("***** 添加代理后 ******");
        StaticProxy proxy = new StaticProxy(hi);
        proxy.sayHello(name);

        System.out.println("************ JDK动态代理 ************");
        PeopleInvocationHandler handler = new PeopleInvocationHandler(hi);
        IHello jdkProxy = (IHello) Proxy.newProxyInstance(hi.getClass().getClassLoader(), hi.getClass().getInterfaces(), handler);
        jdkProxy.sayHello(name);
        jdkProxy.sayGoodBye(name);

        IStudy studyProxy = (IStudy) Proxy.newProxyInstance(hi.getClass().getClassLoader(), hi.getClass().getInterfaces(), handler);
        studyProxy.studyEnglish(name);
        studyProxy.studyMath(name);
    }
}
